package itheima05;

import java.util.*;

/**
 * @author xxx
 * @date 2020/12/22 14:05
 * @description
 */
public class Test {
    public static void main(String[] args) {
        //准备牌：54张牌存在Map中
        Map<Integer,String> map=getpoker();
        //洗牌：将Map的键放到List集合中，然后打乱
        List<Integer> list=hashpoker(map);
        //发牌，将list集合留3张做底牌，其余分发给3位玩家
        List<Player>list1=sendpoker(list);
        //看牌，将3为玩家和底牌对应的牌类依次输出
        lookpoker(list1,map);
    }
  //准备牌
    public static  Map<Integer,String> getpoker(){
        Map<Integer,String>map=new HashMap();
        List<String>list1=new ArrayList();

        List<String>list2=new ArrayList();

        Collections.addAll(list1,"♥","♠","♣","♦");
        Collections.addAll(list2,"3-4-5-6-7-8-9-10-J-Q-K-A-2".split("-"));
        int i=0;

        for (String s : list1) {
            for (String s1 : list2) {
                String a=s+s1;
                map.put(i,a);
                i++;
            }
        }

        map.put(i++,"大王");
        map.put(i,"小王");
        //
        System.out.println("所有牌:"+map);
        return map;
    }

    //洗牌
    public  static  List<Integer>  hashpoker(Map<Integer,String> map){
       List<Integer> list=new ArrayList(map.keySet());
       Collections.shuffle(list);
        System.out.println(list);
       return  list;
    }
    //发牌
    public static List<Player> sendpoker(List<Integer> list){
        List<Player>list1=new ArrayList<>();

        Player player1=new Player("w");
        Player player2=new Player("k");
        Player player3=new Player("q");
        Player bottom=new Player("底牌");
        System.out.println(list);
        for (int i = 0; i < list.size(); i++) {
            if(i>50){
               bottom.getList().add(list.get(i));
             }else  if(i%3==0){
                player1.getList().add(list.get(i));
             }else  if(i%3==1){
                player2.getList().add(list.get(i));
             }else   if(i%3==2){
                player3.getList().add(list.get(i));
            }

        }
            list1.add(bottom);
            list1.add(player1);
            list1.add(player2);
            list1.add(player3);

        System.out.println(player1.getList());

        return list1;
    }

    public static  void  lookpoker(List<Player> list,Map<Integer,String>map ){
        for (Player player : list) {
            System.out.print(player.getPlayerName()+":  ");
            Collections.sort(player.getList());

            for (Integer integer : player.getList()) {
                System.out.print(map.get(integer)+" ");
            }
            System.out.println("");
        }
    }
}
